package org.jeecg.modules.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.demo.bean.vo.OrgTreeVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.system.entity.SysUser;

import java.util.List;

/**
 * @author : willian fu
 * @date : 2022/6/27
 */
public interface WflowUsersMapper extends BaseMapper<SysUser> {

    /**
     * 查询该部门下的所有用户
     * @param deptId 部门ID
     * @return 用户列表 type为固定值user
     */
    @Select("SELECT ou.id id,ou.phone phone, ou.realname `name`, 'user' AS 'type'" +
            "FROM sys_user_depart oud LEFT JOIN sys_user ou ON ou.id = oud.user_id " +
            "WHERE oud.dep_id = #{deptId} AND ou.del_flag = '0'")
    List<OrgTreeVo> selectUsersByDept(@Param("deptId") String deptId);


    @Select("SELECT ou.id id,ou.phone phone, ou.realname `name`, 'user' AS 'type', ou.avatar " +
            "FROM zy_user_depart oud LEFT JOIN sys_user ou ON ou.id = oud.user_id " +
            "WHERE oud.dep_id = #{deptId} AND ou.del_flag = '0'")
    List<OrgTreeVo> selectUsersByDeptSys(@Param("deptId") String deptId);


    @Select("SELECT ou.id id, ou.phone phone,ou.realname `name`, 'user' AS 'type', ou.avatar " +
            "FROM zy_user_depart oud LEFT JOIN zy_user ou ON ou.id = oud.user_id " +
            "WHERE oud.dep_id = #{deptId} AND ou.del_flag = '0'")
    List<OrgTreeVo> selectUsersByDeptZy(@Param("deptId") String deptId);

    /**
     * 通过拼音搜索用户，全拼和拼音首字母模糊搜索
     * @param py 拼音
     * @return 搜索的用户列表 type为固定值user
     */
    @Select("SELECT ou.user_id id, ou.user_name name, ou.avatar FROM sys_user ou " +
            "WHERE ou.user_name LIKE '%${py}%' OR pingyin LIKE '%${py}%' OR py LIKE '%${py}%' AND ou.del_flag = '0'")
    List<OrgTreeVo> selectUsersByPy(@Param("py") String py);
}
